All Questions
Tagged with programming-practicesobject-oriented
88 questions
0votes
1answer
368views
How best to share common steps between services while allowing them to provide their own behaviour
I've started working on a C# codebase. There are three services which run the same set of steps of three kinds of objects, each returning IResult: public IResult FooService(Foo foo) { ... } public ...
2votes
4answers
3kviews
I wrote a class with "init" method. Should I call it from other class methods? Or leave it to the object user? (Code Design)
I have a java class with an init method. It's different from the constructor. The constructor just initializes the variables/fields. The init method connects to a database and performs some ...
-1votes
2answers
262views
Do I really need TaskManager class? [duplicate]
Background: I'm coding an app, the core idea is simple - I can choose a 'Task' (consists of name, code to perform aka Runnable, progress) through GUI, start it, stop it, start all 'Task's and stop all ...
-1votes
1answer
241views
How to avoid cyclic dependency in UI application
I'm developing an UI application where I ran into an issue with a cyclic dependency. Here is the simplified code, to explain the problem. #include <list> class UiStyle; UiStyle* CreateStyle(); ...
0votes
1answer
564views
Using for_each instead of iterators to avoid iterator invalidation
I am writing a simple custom (special purpose) container and would like to allow for iteration over each element, however, avoid using iterators due to the problem of iterator invalidation. Instead of ...
2votes
1answer
118views
Is it a good software engineering practice to store libraries as attributes of objects?
Suppose I initialize a library, say, in python object - #filename: file_A import file_ class A(): def __init__(self): self.pd = file_.pd self.np = file_.np And suppose the ...
-1votes
1answer
66views
Where is it appropriate to implement the split_array method
I am writing an implementation of a binary search tree and in doing this I need a method that splits an array in two. I am unsure where it is appropriate to place this method. What I mean by "where ...
1vote
2answers
1kviews
Calling methods on objects VS. passing objects as parameters
Which is considered a generally accepted practice? class Image { public void decode(); }; //main Image image; image.decode(); vs class ImageDecoder { public Image run(Image image); }; //main Image ...
-1votes
3answers
175views
How do you enforce rules for the members of a collection in a non-OOP way?
When everything seems to be a collection, how do you enforce rules for members of said collection without the use of an interface? As far as I am aware, in languages that don't fully support OOP ...
8votes
3answers
7kviews
Is it good practice to make everything internal in C#?
In our solution we have a couple of projects, a project for data layer, service layer, business layer. etc. Inside the business layer, we use models to transfer data from classes to classes. Is it ...
2votes
2answers
4kviews
Module with globals or Class with attributes?
Currently I'm working with a lot of modules where the original developers used global variables to control states and to exchange important information between functions, like so: STATE_VAR = 0 def ...
1vote
3answers
909views
Why shouldn't I create a class for every property?
In a particular program I had written, I noticed I had a few classes with this pattern: class IdObject: '''Objects with generated id properties''' def __init__(self, id_generator): ...
-1votes
1answer
329views
What is the programming paradigm when I just use functions in a file to organize my program?
I'm programming a telegram bot with Python and, for a number of reasons, there are no classes in the whole project, just several functions correlated to the the file where they are located. E.g., my ...
3votes
5answers
300views
How do you force developers to define dependencies/arguments if it's bad to put the constructor function in the interface?
I just started reading more about OOP and its design patterns and is confused with this conceptual question. I am too new that I am having second thought that the proper title should be, "when is it ...
7votes
3answers
10kviews
Are there any drawbacks to using a nested class instead of declaring a new one?
I'm doing code review on a change my co-worker made to our Java application, and I've found something I'm not very familiar with - a nested class. From reviewing the code, it seems like the nested ...